package pers.vicxu.mvcrestplus.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.vicxu.mvcrestplus.dao.BookDao;
import pers.vicxu.mvcrestplus.pojo.Book;

import java.util.Date;
import java.util.List;

/**
 * Create by Vic Xu on 7/25/2018
 *
 * @author Vic Xu
 */
@Service("BookServiceImpl")
public class BookServiceImpl implements BookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public List<Book> findAll() {
        return bookDao.findAll();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Book addBook(Book book) {
        book.setPressDate(new Date());
        return bookDao.addBook(book);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteBook(String key) {
        if (bookDao.deleteBook(key)) {
            return true;
        }
        return false;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Book updateBook(Book book) {
        return bookDao.updateBook(book);
    }
}
